package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("supplier")
public class SupplierController {
    @Autowired
    private SupplierService supplierService;

    /*
     * 请求URL：http://localhost:8080/supplier/list
     * 请求参数：Integer page（当前页数）, Integer rows（每页显示的记录数）, String supplierName
     * 请求方式：POST
     * 返回值类型： JSON
     * 返回值：Map<String,Object>
     * Response Example Value：
     */
    @PostMapping("list")
    Map<String, Object> list(Integer page, Integer rows, String supplierName) {

        return supplierService.list(page, rows, supplierName);

    }

    /*
        请求URL：http://localhost:8080/supplier/save?supplierId=1
        请求参数：Supplier supplier
        请求方式：POST
        返回值类型： JSON
        返回值：ServiceVO
        Response Example Value：
        {
            "code": 100,
            "msg": "请求成功",
            "info": null
        }
     */
    @PostMapping("save")
    public ServiceVO saveOrUpdate(@RequestParam(value = "id",required = false) Integer id, Supplier supplier){
         supplierService.saveOrUpdate(id,supplier);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }
    @PostMapping("delete")
    public ServiceVO delete(@RequestParam(value = "ids") Integer[] ids){
        supplierService.delete(ids);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }
}
